<template>
  <d2-container>
    <div class="d2-breadcrumb">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item>图鉴管理</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <el-form :inline="true" class="SearchForm">
      <el-form-item>
        <router-link to="resource/add">
          <el-button type="success">新增图鉴</el-button>
        </router-link>
      </el-form-item>
    </el-form>
    <el-table border :data="tableData.list">
      <el-table-column
        label="序号"

        align="center"
        prop="serial_num"
      ></el-table-column>
      <el-table-column
        label="uri"

        align="center"
        prop="uri"
      ></el-table-column>
      <el-table-column
        label="加成"

        align="center"
        prop="addition"
      ></el-table-column>
      <el-table-column
        label="权重"

        align="center"
        prop="weight"
      ></el-table-column>
      <el-table-column
        label="中文昵称"

        align="center"
        prop="name"
      ></el-table-column>
      <el-table-column
        label="英文昵称"

        align="center"
        prop="ename"
      ></el-table-column>
      <el-table-column label="状态" align="center">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.show" :disabled="true"></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="图像" align="center">
        <template slot-scope="scope">
          <img :src="`http://collect.img.dappbox.finance/${scope.row.uri}`" alt="" style="width:80px">
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <router-link :to="`/resource/edit/${scope.row._id}`">
            <el-button type="text">详情/编辑</el-button>
          </router-link>
          <!-- 不应该有删除，只能进行编辑 -->
          <!-- <el-button
            type="text"
            class="margin-left"
            @click="deleteInfo(scope.row._id)"
            >删除</el-button
          > -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="search"
      @current-change="search"
      :current-page.sync="page"
      :page-sizes="[10, 25, 50, 100]"
      :page-size.sync="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="tableData.count"
    ></el-pagination>
  </d2-container>
</template>

<script>
export default {
  name: '',
  data () {
    return {
      searchForm: {
        user_name: ''
      },
      tableData: {
        list: [],
        count: 0
      },
      page: 1,
      pageSize: 10
    }
  },
  methods: {
    search () {
      let params = {
        page: this.page,
        page_size: this.pageSize,
        ...this.searchForm
      }

      this.$axios.post('/admin/getResourceList', params).then((result) => {
        if (result) {
          this.tableData = result
        } else {
          this.$message.error(result.data.msg)
        }
      })
    },
    reset () {
      this.searchForm = {}
      this.search()
    },
    deleteInfo (id) {
      const _this = this
      this.$confirm('确定删除该条数据？', '确认删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        closeOnPressEscape: false,
        closeOnClickModal: false
      }).then(() => {
        let params = {
          _id: id
        }
        _this.$axios.post('/admin/deleteResource', params).then((res) => {
          if (res) {
            _this.$message({
              message: res.data.msg,
              type: 'error'
            })
          } else {
            _this.$message({
              message: '删除成功',
              type: 'success'
            })
            _this.search()
          }
        })
      })
    }
  },
  created () {
    this.search()
  }
}
</script>

<style scoped lang="scss">
</style>
